package com.newture.lxz.services.impl;

import com.newture.lxz.constant.Constant;
import com.newture.lxz.db.mapper.LdCourtAddressMapper;
import com.newture.lxz.db.mapper.LdPayMapper;
import com.newture.lxz.db.model.LdCourtAddressWithBLOBs;
import com.newture.lxz.db.model.LdPay;
import com.newture.lxz.db.model.LdPayLogWithBLOBs;
import com.newture.lxz.errors.AppException;
import com.newture.lxz.errors.Errors;
import com.newture.lxz.pvg.Pvg;
import com.newture.lxz.services.IPaySrv;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;

@Service("PaySrv")
public class PaySrv implements IPaySrv {

    @Resource
    LdPayMapper ldPayMapper;

    @Override
    public int insert(LdPay obj) {
        BigDecimal payZ = new BigDecimal(0.00);
        obj.setCreator(Pvg.getPvgName());
        obj.setModifier(Pvg.getPvgName());
        obj.setGmtCreated(LocalDateTime.now());
        obj.setGmtModified(LocalDateTime.now());
        obj.setIsDeleted(Constant.NO);
        obj.setVersion(1);
        obj.setPaymentChannel("local");
        obj.setStatus("paid");
        obj.setRefund(payZ);
        obj.setTransactionId("");
        obj.setTotalFee(payZ);
        obj.setFeeType("CNY");
        obj.setResultCode("SUCCESS");
        obj.setErrCode("");
        obj.setErrCodeDes("");
        obj.setTimeEnd(LocalDateTime.now());
        int effectCount = ldPayMapper.insert(obj);
        if(effectCount != 1) {
            throw new AppException(Errors.SAVE_ERR.name(), obj.toString(), "CourtAddressSrv.insert() failed");
        }

        return obj.getId();
    }

    @Override
    public int insertSelective(LdPay obj) {
        return 0;
    }
}
